package com.four.controller;

import com.four.entity.User;
import com.four.service.UserService;
import com.four.util.WebUtil;
import com.four.vo.Result;
import com.four.vo.UserVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * ClassName:UserController
 * Description:
 * date:2022/10/13 12:03
 *
 * @since JDK 1.8
 */
@RestController
@RequestMapping("user")
public class UserController {
    @Autowired
    private UserService userService;
    @PostMapping("/user")
    public Result user(@RequestBody UserVo userVo){
        return userService.findByNameAndPass(userVo.getPhoneNumber(),userVo.getPassword());
    }
    @PostMapping("registration")
    public Result Registration(@RequestBody User user){
        return userService.insert(user);
    }

    @PostMapping("/logout")
    public Result logout(){
        WebUtil.getSession().removeAttribute("user");
        return new Result(200,"退出成功");
    }
    @PostMapping("/getUserInfo")
    public Result getUserInfo(){
        User user = (User) WebUtil.getSession().getAttribute("user");
//        User user1 = new User();
//        user1.setRealname(user.getRealname());
        return new Result(200,"success",user);
    }

}
